class HouseItem:
    def __init__(self, name, area):
        '''
        初始化方法
        :param name: 家具名字
        :param area: 家具占地面积
        '''
        self.name = name
        self.area = area

    def __str__(self):
        return '[%s] 占地 %.2f' %(self.name, self.area)


class House:
    def __init__(self,house_type,area):
        '''
        房子初始化方法
        :param house_type:
        :param area:
        '''
        self.house_type = house_type
        self.area = area
        self.free_area = area # 剩余可用面积
        self.item_list = []  # 家具列表

    def __str__(self):
        return ('户型：%s\n总面积：%.2f\n[剩余：%.2f]\n家具%s'
                %(self.house_type, self.area, self.free_area, self.item_list))

    def add_item(self,item:HouseItem):  # 通过冒号：对象类型  加注解
        if self.free_area >= item.area:
            self.free_area -= item.area
            self.item_list.append(item.name)
        else:
            print('剩余空间不足，放家具失败')
            return


if __name__ == '__main__':
    bed = HouseItem('席梦思',4)
    chest = HouseItem('衣柜',2)
    table = HouseItem('餐桌',1.5)
    print(bed)
    print(chest)
    print(table)
    house = House('两室一厅',30)
    house.add_item(bed)
    house.add_item(chest)
    house.add_item(table)
    print(house)